<script>
import {
	getStorage,
	removeStorage
} from '@/util/auth.js';
import {
	getWxLoginCode
} from '@/util/user.js'
export default {
	onLaunch: function () {
		uni.loadFontFace({
			source: 'url("https://job-supermarket-1306862033.cos.ap-chengdu.myqcloud.com/uniapp/%E6%96%B9%E6%AD%A3%E6%B1%89%E7%9C%9F%E5%B9%BF%E6%A0%87%E7%AE%80%E4%BD%93.TTF")',
			family: 'FangZhengHanZhenGuangBiaoJianTi',
			global: true,
		})
		let _this = this;
		uni.addInterceptor('navigateTo', {
			invoke(e) {
				return _this.watchRouter(e);
			}
		})
		uni.addInterceptor('redirectTo', {
			invoke(e) {
				return _this.watchRouter(e);
			}
		})
		uni.addInterceptor('reLaunch', {
			invoke(e) {
				return _this.watchRouter(e);
			}
		})
		uni.addInterceptor('switchTab', {
			invoke(e) {
				return _this.watchRouter(e);
			}
		})
		//自动登录
		// if (!this.$store.getters.token) {
		// 	getWxLoginCode().then((code) => {
		// 		uni.showLoading({
		// 			title: '加载中',
		// 			mask: true,
		// 		})
		// 		this.$store.dispatch('user/getWxLoginCode', code).catch(() => {
		// 			uni.showModal({
		// 				title: '提示',
		// 				content: '获取信息失败，请尝试重新进入小程序，否则功能无法正常使用',
		// 			})
		// 		})
		// 	})
		// } else {
		// 	this.$store.dispatch('user/getUser');
		// }
		// this.$store.dispatch('position/getPosition')
	},
	methods: {
		watchRouter(e) {
			let url = e.url;
			const index = url.indexOf('?');
			url = index == -1 ? url : url.slice(0, index);
			const hasToken = getStorage('token');
			const user = getStorage('user')
			const whiteList = [
				'/pages/pay_success/pay_success', '/pages/index/index', '/'
			];
			// if (hasToken) {
			// 	return true
			// } else {
			// 	if (whiteList.includes(url)) {
			// 		return true
			// 	} else {
			// 		uni.showModal({
			// 			title: '提示',
			// 			content: '需要先登录！',
			// 			cancelText: '先逛逛',
			// 			confirmText: '去登录',
			// 			success(res) {
			// 				if (res.confirm) {
			// 					uni.navigateTo({
			// 						url: '/pages/login/login'
			// 					})
			// 				} else {
			// 					uni.navigateBack();
			// 				}
			// 			}
			// 		})
			// 	}
			// }
			return true;
		}
	},
	
}
</script>

<style lang="scss">
@import url("@/static/iconfont/iconfont.css");

.FZHZGBJ {
	font-family: 'FangZhengHanZhenGuangBiaoJianTi';
}

button {
	padding: 0;
	background: none;
	line-height: normal !important;
}

button::after {
	border: none !important;
}

view,
text,
navigator,
input,
picker,
button,
scroll-view,
textarea,
label,
image {
	box-sizing: border-box;
}

.input-placeholder {
	color: #686868;
	font-weight: normal;
	// display: flex;
	// justify-content: flex-end;
	font-size: 30rpx
}

.empty {
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #313131;
	font-size: 28rpx;
	margin: 30rpx auto;
}

page {
	min-height: calc(100vh - var(--window-bottom) - var(--window-top));
	background: $background-color;
}

.page {
	width: 100%;
	min-height: calc(100vh - var(--window-bottom) - var(--window-top));
}

.input-placeholder {
	color: #686868;
	font-weight: normal;
}

.btn {
	width: 330rpx;
	height: 90rpx;
	border-radius: 60px;
	display: flex;
	align-items: center;
	justify-content: center;
}

.btn-small {
	width: 160rpx;
	height: 64rpx;
	border-radius: 60px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 26rpx;
}

.normal {
	color: #fff;
	background: linear-gradient(to right, #4A8DFF, #4A8DFF);
}

.red {
	color: #fff;
	background: #ff3e25;
}

.green {
	color: #fff;
	background: #14aa2d;
}

.cancel {
	color: $theme-color;
	border: 1px solid $theme-color;
}

.disabled {
	color: #fff;
	background: #999;
	border: none;
}

.full {
	color: $theme-color;
	background: #EDF3FF;
}

image {
	display: block;
}
</style>